package problems.solved;

import java.util.HashSet;
import java.util.Set;

import utils.Utils;

//TODO optimize.
public class Problem21 {
	public static void main(String[] args) {
		Set<Integer> amicable = new HashSet<Integer>();
		
		for (int a = 1; a <= 10000; a++) {
			int da = (int) Utils.sumOfIntegers(Utils.divisors(a));
			if (a != da) {
				int db = (int) Utils.sumOfIntegers(Utils.divisors(da));
				if (db == a) {
					amicable.add(a);
					amicable.add(da);
				}
			}
		}
		System.out.println("sum=" + Utils.sumOfIntegers(amicable));
	}
}
